<template>
  <div>
    <van-index-bar>
      <div v-for="v in car" :key="v.id">
        <van-index-anchor :index="v.title" />
        <van-cell
          :title="item.name"
          v-for="item in v.list"
          :key="item.id"
          @click="toCarDetail(item.name, item.id)"
        />
      </div>
    </van-index-bar>
  </div>
</template>


<script>
import { mapState, mapActions } from "vuex";
export default {
  name: "selectCar",
  computed: {
    ...mapState("car", {
      car: (state) => state.car,
    }),
  },
  methods: {
    ...mapActions("car", ["fetchCar"]),
    toCarDetail(name, id) {
      // this.$router.push(`/car/${name}/${id}`);
      this.$router.push({
        name: "car",
        params: {
          name,
          id,
        },
      });
    },
  },
  created() {
    this.fetchCar();
  },
};
</script>